package com.woniuxy.controller;

import java.text.SimpleDateFormat;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.woniuxy.entity.Book;
import com.woniuxy.service.BookService;

@Controller
@RequestMapping("/book")
public class BookController {
	@Autowired
	BookService bookService;
	@RequestMapping("/books")
	@ResponseBody
	public List<Book> selectAll(){
		List<Book> books =bookService.selectBookAll();
	//System.out.println(books);
		return books;
	}
	
	@RequestMapping("/book")
	@ResponseBody
	public Book selectBookByBid(int bid){
		//Book book=bookService.selectBookByBid(bid);
	System.out.println(bookService.selectBookByBid(bid));
		return bookService.selectBookByBid(bid);
		
	}
	
	@RequestMapping("/delete")
	@ResponseBody
	public String delete(@RequestParam("bid") int bid) {
		System.out.println(bid);
		bookService.deleteBookByBid(bid);
		return "success";
	}
	
	@RequestMapping("/insert")
	@ResponseBody
	public String insert(@RequestBody Book book) {
		System.out.println(book);
		bookService.insertBook(book);
		return "success";
	}
	
	@RequestMapping("/update")
	@ResponseBody
	public String update(@RequestBody Book book) {
	    //System.out.println(book);
		bookService.updateBookByBid(book);
		return "success";
		
	}
}
